<template>
  <div class="container">
    <!-- <Modal v-model="isShowModal"> </Modal>
    <button @click="isShowModal = !isShowModal">控制modal是否显示</button> -->
    <!-- 文章分类栏 -->
    <!--
      swipeable 手机端支持滑动切换页签内容
      animated 开启切换时的过场动画
     -->
    <van-tabs swipeable animated v-model="activeIndex">
      <!-- 默认插槽 =》 van-tab标识页签名+页签内容 -->
      <van-tab :key="item.id" v-for="item in channelList" :title="item.name">
        <!-- 可滚动内容区域=》默认插槽 -->
        <ArticleList :channelId="item.id" />
      </van-tab>
    </van-tabs>
    <!-- 右侧图标 -->
    <span class="bar_btn" @click="show = true">
      <van-icon name="wap-nav"></van-icon>
    </span>
    <!-- 放到根元素之前 -->
    <!-- <ChannelEdit
      v-model="show"
      :myChannel="channelList"
      :activeIndex="activeIndex"
      @enter-channel="activeIndex = $event"
    /> -->
    <!--
      .sync 同步修改数据
      用法：
      1. 传入变量 => :属性名.sync="变量"(简化写法)
      2. 修改变量 =>  this.$emit('update:属性名',data)
      注意：vue3不在支持
     -->
    <ChannelEdit
      v-model="show"
      :myChannel="channelList"
      :activeIndex.sync="activeIndex"
    />
  </div>
</template>

<script>
// 测试axios封装
// import request from '../../utils/request'
// 测试模块化
// import dfn, { a, fn, axios } from '@/utils/test.js'
// console.log(dfn, a, fn, axios)
// 导入获取频道数据后台接口方法
import { getUserChannelApi } from '../../api/channel'
import ArticleList from './components/articleList.vue'
import ChannelEdit from './components/channel-edit.vue'

export default {
  components: {
    ArticleList,
    ChannelEdit

  },
  data () {
    return {
      activeIndex: 0, // 当前选中页签的索引值
      // isShowModal: false,
      show: false, // 控制频道编辑弹层显示隐藏
      channelList: []
    }
  },
  created () {
    this.getChannel()
  },
  methods: {
    // 获取频道数据
    async getChannel () {
      const { data } = await getUserChannelApi()
      console.log(data.channels)
      this.channelList = data.channels
    }

  }
}
</script>

<style scoped lang='less'>
// 覆盖有赞页签组件的默认样式
.van-tabs {
  height: 100%;
  display: flex;
  flex-direction: column;
  // 自定义tab样式=》/deep/覆盖子组件的样式
  /deep/ .van-tabs__wrap {
    height: 36px;
    padding-right: 36px;
    .van-tab {
      line-height: 36px;
    }
    .van-tabs__line {
      background-color: #fc6627;
      height: 2px;
    }
  }
  /deep/ .van-tabs__content {
    flex: 1;
    overflow: hidden;
  }
  /deep/ .van-tab__pane {
    height: 100%;
    // 控制列表区域可滚动
    .scroll-wrapper {
      height: 100%;
      overflow-y: auto;
    }
  }
}
.bar_btn {
  width: 36px;
  height: 35px;
  position: absolute;
  top: 0;
  right: 0;
  font-size: 20px;
  text-align: center;
  line-height: 40px;
  box-shadow: -6px -6px 8px #ddd;
}
</style>
